package com.moehu.back.controller.app;

import com.moehu.back.annotation.AppRestController;
import com.moehu.back.annotation.UserLoginToken;
import com.moehu.back.controller.base.BaseService;
import com.moehu.back.model.CommentModel;
import com.moehu.back.model.PagingModel;
import com.moehu.back.model.ResultModel;
import com.moehu.back.model.UserModel;
import com.moehu.back.model.response.LoginResponseModel;
import com.moehu.back.model.response.PagingResponseModel;
import com.moehu.back.service.impl.CommentServiceImpl;
import com.moehu.back.service.impl.UserServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping(value = "/comment")
@AppRestController
@Api(tags = "Comment 评论相关的接口")
public class CommentController extends BaseService {

    @Autowired
    private CommentServiceImpl commentService;

    @UserLoginToken
    @ApiOperation(value="【作品和动态共用】发布&回复评论", notes="用户发布评论（一级回复） & 回复某个人的评论（二级回复）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "opus_id", value = "评论作品时，必传作品的id，如果是动态页面那么该字段需要为：'' ", required = false, dataType = "Number"),
            @ApiImplicitParam(name = "dynamic_id", value = "评论动态时，必传动态的id，如果是作品页面那么该字段需要为：'' ", required = false, dataType = "Number"),
            @ApiImplicitParam(name = "comment_content", value = "评论的内容", required = true, dataType = "String"),
            @ApiImplicitParam(name = "comment_reply_id", value = "一级回复（发布评论）的时候默认传 0，二级回复时候永远传1级评论id", required = true, dataType = "Number"),
            @ApiImplicitParam(name = "comment_to_username", value = "回复去向的用户名，例如，张三回复李四，那么传李四，用户发布评论的时候字段可以为空", required = true, dataType = "String"),
            @ApiImplicitParam(name = "comment_type", value = "评论的类型：1 作品的评论，2 动态的评论", required = true, dataType = "Number"),
    })
    @PostMapping("/add")
    public ResultModel pushComment(@RequestBody CommentModel comment) {
        return commentService.pushComment(comment);
    }


    @ApiOperation(value="【作品和动态共用】获取所有评论", notes="获取作品和动态的所有评论")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "opus_id", value = "获取作品评论时，必传作品的id，如果是动态页面那么该字段需要为：'' ", required = false, dataType = "Number"),
            @ApiImplicitParam(name = "dynamic_id", value = "获取动态评论时，必传动态的id，如果是作品页面那么该字段需要为：'' ", required = false, dataType = "Number"),
            @ApiImplicitParam(name = "page", value = "请求的页数", required = false, dataType = "Number", defaultValue="1"),
            @ApiImplicitParam(name = "count", value = "每页作品数，默认15", required = false, dataType = "Number", defaultValue="15"),
            @ApiImplicitParam(name = "comment_type", value = "评论的类型：1 作品的评论，2 动态的评论", required = true, dataType = "Number"),
    })
    @PostMapping("/list")
    public ResultModel<PagingResponseModel<List<CommentModel>>> list(@RequestBody Map<String, Integer> Opus) {
        if (Opus.get("page")==null) {
            Opus.put("page",1);
        }

        if (Opus.get("count") == null) {
            Opus.put("count",15);
        }
        return commentService.all(Opus);
    }


    @UserLoginToken
    @ApiOperation(value="【作品和动态共用】删除评论", notes="删除评论")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "opus_id", value = "作品的id", required = true, dataType = "Number"),

            @ApiImplicitParam(name = "comment_id", value = "评论的id", required = true, dataType = "Number"),
            @ApiImplicitParam(name = "level", value = "被删除评论的等级，取值范围：1（一级评论），2：（二级评论）", required = true, dataType = "Number"),
    })
    @PostMapping("/delete")
    public ResultModel<List<CommentModel>> delete(@RequestBody Map<String, Integer> Comment) {
        return commentService.delete(Comment);
    }

    @UserLoginToken
    @ApiOperation(value="【作品和动态共用】举报评论", notes="用户举报某条评论")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "comment_id", value = "评论的id", required = true, dataType = "Number"),
            @ApiImplicitParam(name = "report_text", value = "举报的原因", required = true, dataType = "String"),
    })
    @PostMapping("/report")
    public ResultModel<List<CommentModel>> report(@RequestBody Map<String, Integer> Comment) {
        return commentService.report(Comment);
    }
}
